package main

import (
	"fmt"
)

type Reader interface {
	Read()
}

type MyWriter interface {
	Writer()
}
type IoReaderWriter interface {
	Reader
	MyWriter
	IoReader()
}

type FileWriter struct {
	Name string
}

func (fw *FileWriter) Writer() {
	fmt.Println("file writer")
}

type DatabaseWriter struct{}

func (dw *DatabaseWriter) Writer() {
	fmt.Println("database writer")
}

type Writer struct {
	MyWriter
}

func Add(a, b interface{}) interface{} {
	defer func() {
		a2 := recover()
		fmt.Println(a2)
	}()
	//通过断言实现类型转换
	ai, ok := a.(int) //括号里面是想转换的类型
	if !ok {
		panic("a type is error")
	}
	bi, ok := b.(int)
	if !ok {
		panic("b type is error")
	}
	return ai + bi
}

func mPrint(data ...interface{}) {

	for _, v := range data {
		fmt.Println(v)
	}
}

func main() {

	data := []interface{}{
		1, 2, "4", "3", "a",
	}
	data1 := []string{"a", "b", "c"}

	mPrint(data)
	mPrint(data1)

	//
	//w := Writer{&FileWriter{}}
	//w.MyWriter.Writer()

	//a := 1
	//b := 2.2
	//Add(a, b)

}
